<?php

/**
 * ECSHOP mobile首页
 * ============================================================================
 * * 版权所有 2005-2012 上海商派网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.ecshop.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: liuhui $
 * $Id: index.php 15013 2010-03-25 09:31:42Z liuhui $
*/

define('IN_ECS', true);
define('ECS_ADMIN', true);

require(dirname(__FILE__) . '/includes/init.php');

include_once(ROOT_PATH . '/includes/lib_goods.php');  //添加
$computer=isset($_REQUEST['computer'])? intval($_REQUEST['computer']):0;
if($computer==1){
    $Loaction = '../index.php?computer=1';
    ecs_header("Location: $Loaction\n");

    exit;
}

$ads_id = $GLOBALS['db']->getOne('SELECT position_id FROM ' . $GLOBALS['ecs']->table('ad_position') . ' WHERE `position_name` = "手机端首页轮播图"');
$time = gmtime();
$sql  = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('ad') . ' AS a '.
    'LEFT JOIN ' . $GLOBALS['ecs']->table('ad_position') . ' AS p ON a.position_id = p.position_id ' .
    "WHERE enabled = 1 AND start_time <= '" . $time . "' AND end_time >= '" . $time . "' ".
    "AND a.position_id = '" . $ads_id . "' " ;
$num = $GLOBALS['db']->GetOne($sql);
$ads = array(
    'id' => $ads_id,//广告位置id
    'num' => $num
);

$our_ads =insert_ads_mobile($ads);

$smarty->assign('our_ads',$our_ads);

/***酷评 start**/
$row_1 = array();
$sql_comment = "SELECT count(*) as num,g.market_price, g.goods_name,g.shop_price,g.goods_img,g.goods_id FROM ".$ecs->table('comment')." as c LEFT JOIN ".$ecs->table('goods')."  as g on c.id_value=g.goods_id where c.comment_rank=5 and c.status=1 and c.comment_type=0 GROUP BY c.id_value ORDER BY num desc";

$row_1 = $GLOBALS['db']->getALL($sql_comment);
$comment_list_top = array();
$num = count($row_1);
if($num>0)
{
    if($num<3){
        for($i=0;$i<$num;$i++){
            if($row_1[$i]){
                $comment_list_top[] = $row_1[$i];
            }
        }
    }else{
        for($i=0;$i<3;$i++){
            if($row_1[$i]){
                $comment_list_top[] = $row_1[$i];
            }
        }
    }

}

$smarty->assign('comment_list_top',$comment_list_top);

/***酷评 end ***/


/**最新商品 by 周全 start***/

$new_goods = get_recommend_goods('new');
$new_num = count($new_goods);

if ($new_num > 0)
{
    $i = 0;
    foreach  ($new_goods as $key => $new_data)
    {
        $new_goods[$key]['shop_price'] = encode_output($new_data['shop_price']);
        $new_goods[$key]['name'] = encode_output($new_data['name']);
        /*if ($i > 2)
        {
            break;
        }*/
        $i++;
    }

}
/**best_goods数量限制 start**/
$new_goods_1 = array();
for($n=0;$n<3;$n++)
{
    $new_goods_1[] = $new_goods[$n];
}
/**best_goods数量限制 end**/

$smarty->assign('new_goods' , $new_goods_1);

/**最新商品 by 周全 end***/

$best_goods = get_recommend_goods('best');
$best_num = count($best_goods);
$smarty->assign('best_num' , $best_num);
if ($best_num > 0)
{
    $i = 0;
    foreach  ($best_goods as $key => $best_data)
    {
        $best_goods[$key]['shop_price'] = encode_output($best_data['shop_price']);
        $best_goods[$key]['name'] = encode_output($best_data['name']);

        $i++;
    }

}
/**best_goods数量限制 start**/
$best_goods_1 = array();
for($n=0;$n<3;$n++)
{
    $best_goods_1[] = $best_goods[$n];
}
/**best_goods数量限制 end**/
$smarty->assign('best_goods' , $best_goods_1);


/**best_goods数量限制数量限制 end**/

/* 热门商品 */
$hot_goods = get_recommend_goods('hot');
$hot_num = count($hot_goods);
$smarty->assign('hot_num' , $hot_num);
if ($hot_num > 0)
{
    $i = 0;
    foreach  ($hot_goods as $key => $hot_data)
    {
        $hot_goods[$key]['shop_price'] = encode_output($hot_data['shop_price']);
        $hot_goods[$key]['name'] = encode_output($hot_data['name']);

        $i++;
    }

}
/**热门商品前台传值数量限制 start**/
$hot_goods_1 = array();
for($n=0;$n<3;$n++)
{
    $hot_goods_1[] = $hot_goods[$n];
}
$smarty->assign('hot_goods' , $hot_goods_1);


/**热门商品前台传值数量限制 end**/
$promote_goods = get_promote_goods();
$promote_num = count($promote_goods);
$smarty->assign('promote_num' , $promote_num);
if ($promote_num > 0)
{
    $i = 0;
    foreach ($promote_goods as $key => $promote_data)
    {
        $promote_goods[$key]['shop_price'] = encode_output($promote_data['shop_price']);
        $promote_goods[$key]['name'] = encode_output($promote_data['name']);

        $i++;
    }
    $smarty->assign('promote_goods' , $promote_goods);
}

$pcat_array = get_categories_tree();
foreach ($pcat_array as $key => $pcat_data)
{
    $pcat_array[$key]['name'] = encode_output($pcat_data['name']);
    if ($pcat_data['cat_id'])
    {
        if (count($pcat_data['cat_id']) > 3)
        {
            $pcat_array[$key]['cat_id'] = array_slice($pcat_data['cat_id'], 0, 3);
        }
        foreach ($pcat_array[$key]['cat_id'] as $k => $v)
        {
            $pcat_array[$key]['cat_id'][$k]['name'] = encode_output($v['name']);
        }
    }
}
$smarty->assign('pcat_array' , $pcat_array);
$brands_array = get_brands();
if (!empty($brands_array))
{
    if (count($brands_array) > 3)
    {
        $brands_array = array_slice($brands_array, 0, 10);
    }
    foreach ($brands_array as $key => $brands_data)
    {
        $brands_array[$key]['brand_name'] = encode_output($brands_data['brand_name']);
    }
    $smarty->assign('brand_array', $brands_array);
}

$article_array = $db->GetALLCached("SELECT article_id, title FROM " . $ecs->table("article") . " WHERE cat_id != 0 AND is_open = 1 AND open_type = 0 ORDER BY article_id DESC LIMIT 0,4");
if (!empty($article_array))
{
    foreach ($article_array as $key => $article_data)
    {
        $article_array[$key]['title'] = encode_output($article_data['title']);
    }
    $smarty->assign('article_array', $article_array);
}
if ($_SESSION['user_id'] > 0)
{
    $smarty->assign('user_name', $_SESSION['user_name']);
}

if (!empty($GLOBALS['_CFG']['search_keywords']))
{
    $searchkeywords = explode(',', trim($GLOBALS['_CFG']['search_keywords']));
}
else
{
    $searchkeywords = array();
}
$smarty->assign('searchkeywords', $searchkeywords);

$smarty->assign('wap_logo', $_CFG['wap_logo']);
$smarty->assign('footer', get_footer());

/****限时抢购 start***/
$miaosha_info = index_get_miaosha();
$miaosha_num = count($miaosha_info);
$miaosha_info_1 = array();
if(!empty($miaosha_info))
{
    if($miaosha_num)
    {
        if($miaosha_num<3){
            for($i=0;$i<$miaosha_num;$i++)
            {
                if($miaosha_info[$i]!=null){
                    $miaosha_info_1[] = $miaosha_info[$i];/**目前只放三个 前页需要12个**/
                }
            }
        }else{
            for($i=0;$i<3;$i++)
            {
                if($miaosha_info[$i]!=null){
                    $miaosha_info_1[] = $miaosha_info[$i];/**目前只放三个 前页需要12个**/
                }
            }
        }
    }
}
$smarty->assign('miaosha_info',$miaosha_info_1);

/****限时抢购 start***/

$smarty->assign('user_name',$_SESSION['user_name']);

$smarty->display("index.html");



?>
